/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author HOANG ANH
 */
@Entity
@Table(name = "NewsEvents")
@NamedQueries({
    @NamedQuery(name = "NewsEvents.findAll", query = "SELECT n FROM NewsEvents n"),
    @NamedQuery(name = "NewsEvents.findByNewsID", query = "SELECT n FROM NewsEvents n WHERE n.newsID = :newsID"),
    @NamedQuery(name = "NewsEvents.findByNewsName", query = "SELECT n FROM NewsEvents n WHERE n.newsName = :newsName"),
    @NamedQuery(name = "NewsEvents.findByNewsTopic", query = "SELECT n FROM NewsEvents n WHERE n.newsTopic = :newsTopic"),
    @NamedQuery(name = "NewsEvents.findByCreatedTime", query = "SELECT n FROM NewsEvents n WHERE n.createdTime = :createdTime")})
public class NewsEvents implements Serializable {

    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "News_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer newsID;
    @Basic(optional = false)
    @Column(name = "News_Name")
    private String newsName;
    @Basic(optional = false)
    @Column(name = "News_Topic")
    private String newsTopic;
    @Basic(optional = false)
    @Column(name = "Created_Time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdTime;
    @Transient
    private String formatedDate;

    public String getFormatedDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yyyy");
        formatedDate = sdf.format(createdTime);
        return formatedDate;
    }

    public void setFormatedDate(String formatedDate) {
        this.formatedDate = formatedDate;
    }

    public NewsEvents() {
        createdTime = new Date();
    }

    public NewsEvents(Integer newsID) {
        this.newsID = newsID;
    }

    public NewsEvents(Integer newsID, String newsName, String newsTopic, Date createdTime) {
        this.newsID = newsID;
        this.newsName = newsName;
        this.newsTopic = newsTopic;
        this.createdTime = createdTime;
    }

    public Integer getNewsID() {
        return newsID;
    }

    public void setNewsID(Integer newsID) {
        Integer oldNewsID = this.newsID;
        this.newsID = newsID;
        changeSupport.firePropertyChange("newsID", oldNewsID, newsID);
    }

    public String getNewsName() {
        return newsName;
    }

    public void setNewsName(String newsName) {
        String oldNewsName = this.newsName;
        this.newsName = newsName;
        changeSupport.firePropertyChange("newsName", oldNewsName, newsName);
    }

    public String getNewsTopic() {
        return newsTopic;
    }

    public void setNewsTopic(String newsTopic) {
        String oldNewsTopic = this.newsTopic;
        this.newsTopic = newsTopic;
        changeSupport.firePropertyChange("newsTopic", oldNewsTopic, newsTopic);
    }

    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        Date oldCreatedTime = this.createdTime;
        this.createdTime = createdTime;
        changeSupport.firePropertyChange("createdTime", oldCreatedTime, createdTime);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (newsID != null ? newsID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof NewsEvents)) {
            return false;
        }
        NewsEvents other = (NewsEvents) object;
        if ((this.newsID == null && other.newsID != null) || (this.newsID != null && !this.newsID.equals(other.newsID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entities.NewsEvents[newsID=" + newsID + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
